<template>
  <view class="">
    <u-section v-if="showSection" class="section" title="基本信息" :right="false"></u-section>
    <u-cell-group>
      <u-cell-item
        v-show="selectedFields.includes(1) || displayAll"
        required
        :arrow="false"
        :title="level != 3 ? addPrefix('经销商名称') : '门店名称'"
      >
        <u-input
          :customStyle="customStyle"
          inputAlign="right"
          placeholder="请输入经销商名称"
          v-model="form.Dealer_BaseInfo.Name"
        ></u-input>
      </u-cell-item>
      <u-cell-item v-if="showAccount" :arrow="false" :title="level != 3 ? addPrefix('经销商代码') : '门店代码'">
        <u-input
          :customStyle="customStyle"
          inputAlign="right"
          placeholder="经销商代码"
          v-model="form.Dealer_BaseInfo.Account"
        ></u-input>
      </u-cell-item>
      <u-cell-item
        v-show="selectedFields.includes(2) || displayAll"
        :arrow="false"
        :title="level != 3 ? addPrefix('经销商简称') : '门店简称'"
      >
        <u-input
          :customStyle="customStyle"
          inputAlign="right"
          placeholder="请输入经销商简称"
          v-model="form.Dealer_BaseInfo.Referred"
        ></u-input>
      </u-cell-item>
      <u-cell-item
        v-show="selectedFields.includes(3) || displayAll"
        required
        :arrow="false"
        :title="addPrefix('负责人')"
      >
        <u-input
          :customStyle="customStyle"
          inputAlign="right"
          placeholder="请输入负责人"
          v-model="form.Dealer_BaseInfo.NickName"
        ></u-input>
      </u-cell-item>
      <u-cell-item
        v-show="selectedFields.includes(4) || displayAll"
        required
        :arrow="false"
        :title="addPrefix('手机号')"
      >
        <u-input
          :customStyle="customStyle"
          inputAlign="right"
          placeholder="请输入手机号"
          v-model="form.Dealer_BaseInfo.Mobile"
        ></u-input>
      </u-cell-item>
      <block v-if="selectedFields.includes(5) || displayAll">
        <u-cell-item required :arrow="false" :title="addPrefix('公司地址')" v-if="loadCity">
          <city-select v-model="areaCode" @city-change="onCityChange"></city-select>
          <u-input inputAlign="right" v-model="form.Dealer_BaseInfo.Address"></u-input>
        </u-cell-item>
        <u-cell-item :arrow="false">
          <view class="u-font-9 u-text-left">
            *务必详细确保能收到快递（不必在详细地址栏填写省、市、区，只需填写街道名称，门牌号码，楼层和房间号等信息）
          </view>
        </u-cell-item>
      </block>

      <block v-if="level == 3">
        <u-cell-item title="门店位置" :arrow="false" v-if="selectedFields.includes(31) || displayAll">
          <u-input
            type="select"
            :value="location.label"
            placeholder="请选择"
            input-align="right"
            @click="showLocationPicker = true"
          ></u-input>
          <u-input inputAlign="right" v-model="form.Dealer_OtherInfo.Store_Location_Other"></u-input>
          <u-select
            @confirm="onLocationChange"
            :default-value="[locationIndex]"
            v-model="showLocationPicker"
            :list="Store_Location_List"
            label-name="Value"
            value-name="Key"
            safe-area-inset-bottom
          ></u-select>
        </u-cell-item>
        <u-cell-item v-if="selectedFields.includes(32) || displayAll" title="门店BDR面积" :arrow="false">
          <u-input v-model="form.Dealer_OtherInfo.BDR_Area" input-align="right" placeholder="门店BDR面积"></u-input>
        </u-cell-item>
        <u-cell-item v-if="selectedFields.includes(33) || displayAll" title="店内面积" :arrow="false">
          <u-input v-model="form.Dealer_OtherInfo.Store_Area" input-align="right" placeholder="门店BDR面积"></u-input>
        </u-cell-item>
        <u-cell-item v-if="selectedFields.includes(49) || displayAll" title="门店其他产品占用面积" :arrow="false">
          <u-input
            v-model="form.Dealer_OtherInfo.OtherProductArea"
            input-align="right"
            placeholder="门店BDR面积"
          ></u-input>
        </u-cell-item>
      </block>

      <block v-if="level != 3">
        <block v-if="selectedFields.includes(6) || displayAll">
          <u-cell-item required :border-bottom="false" :arrow="false" :title="addPrefix('证照')">
            <view class="u-flex u-row-right">
              <u-upload
                :show-progress="false"
                ref="licenseUpload"
                :width="240"
                :height="200"
                :file-list="licenseFileList"
                :preview-full-image="true"
                :multiple="false"
                @on-choose-complete="onLicenseChange"
                @on-remove="onRemoveLicense"
                :auto-upload="false"
                :max-count="1"
              ></u-upload>
            </view>
          </u-cell-item>
          <u-cell-item :arrow="false">
            <view class="u-font-9 u-text-left">上传营业执照扫描件/相片，无营业执照的须上传老板的身份证</view>
          </u-cell-item>
        </block>
        <block v-if="selectedFields.includes(7) || displayAll">
          <u-cell-item :arrow="false" :title="addPrefix('经销协议')" :border-bottom="false" style="padding-bottom: 0;">
            <u-radio-group v-model="form.Dealer_OtherInfo.TreatyPhotoType">
              <u-radio :name="1">图片</u-radio>
              <u-radio :name="4">文件</u-radio>
            </u-radio-group>
          </u-cell-item>
          <u-cell-item :arrow="false" style="padding: 10rpx;">
            <view class="u-flex u-row-right" v-if="form.Dealer_OtherInfo.TreatyPhotoType == 1">
              <u-upload
                ref="treatyPhotoUpload"
                :width="240"
                :height="200"
                :file-list="treatyPhotoFileList"
                :preview-full-image="true"
                :multiple="false"
                @on-choose-complete="onTreatyPhotoChange"
                @on-remove="onRemoveTreatyPhoto"
                :auto-upload="false"
                :max-count="1"
              ></u-upload>
            </view>
            <file-picker
              @change="onTreatyPhotoFileChange"
              :maxCount="1"
              v-if="form.Dealer_OtherInfo.TreatyPhotoType == 4"
            ></file-picker>
          </u-cell-item>
        </block>
      </block>

      <!-- 			<u-cell-item v-if="showCCType" required :arrow="false" title="类型">
				<u-radio-group v-model="form.Dealer_OtherInfo.CC_Type">
					<view class="grid-2">
						<u-radio name="1">民用</u-radio>
						<u-radio name="2">商用</u-radio>
						<u-radio name="3">民用+商用</u-radio>
						<u-radio name="4">其他</u-radio>
					</view>
				</u-radio-group>
			</u-cell-item> -->

      <!-- <u-cell-item v-if="showChannelType"  required :arrow="false" title="渠道类型">
				<u-radio-group v-model="form.Dealer_OtherInfo.ChannelType">
					<view class="grid-2">
						<u-radio name="1">渠道</u-radio>
						<u-radio name="2">售后</u-radio>
						<u-radio name="3">渠道+售后</u-radio>
						<u-radio name="4">供应商</u-radio>
						<u-radio name="5">公司</u-radio>
						<u-radio name="6">其他</u-radio>
					</view>
				</u-radio-group>
			</u-cell-item> -->

      <block v-if="showSalesInfo || showBrand">
        <u-cell-item
          v-if="(selectedFields.includes(8) || displayAll) && level != 3"
          required
          :arrow="false"
          :title="addPrefix('属性')"
        >
          <u-radio-group v-model="form.Dealer_OtherInfo.DealerType">
            <view class="grid-2">
              <u-radio
                :label-size="26"
                v-for="(item, index) in metadata.DealerType_BaseList"
                :key="index"
                :name="item.Key"
              >
                {{ item.Value }}
              </u-radio>
            </view>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item
          v-if="selectedFields.includes(9) || displayAll"
          required
          :arrow="false"
          :title="addPrefix('经营品类')"
        >
          <u-checkbox-group @change="onBusinessCategoryChange">
            <view class="grid-2">
              <u-checkbox
                :label-size="26"
                v-model="item.checked"
                v-for="(item, index) in metadata.BusinessCategory_BaseList"
                :name="item.Key"
                :key="index"
              >
                {{ item.Value }}
              </u-checkbox>
            </view>
          </u-checkbox-group>
        </u-cell-item>
        <u-cell-item
          v-if="
            displayAll || (selectedFields.includes(10) || selectedFields.includes(11) || selectedFields.includes(12))
          "
          required
          :arrow="false"
          :title="addPrefix('竞品品牌')"
        >
          <block v-if="selectedFields.includes(10) || displayAll">
            <view class="u-text-left u-p-l-20">BDR品牌数: {{ count_A }}</view>
            <u-checkbox-group @change="onCompetingGoodsBrandAChange">
              <view class="grid-2">
                <u-checkbox
                  :label-size="26"
                  v-model="item.checked"
                  v-for="(item, index) in metadata.CompetingGoodsBrandA_BaseList"
                  :key="index"
                  :name="item.Key"
                >
                  {{ item.Value }}
                </u-checkbox>
              </view>
            </u-checkbox-group>
            <u-line></u-line>
          </block>

          <block v-if="selectedFields.includes(11) || displayAll">
            <view class="u-text-left u-p-l-20">进口品牌数: {{ count_B }}</view>
            <u-checkbox-group @change="onCompetingGoodsBrandBChange">
              <view class="grid-2">
                <u-checkbox
                  :label-size="26"
                  v-model="item.checked"
                  v-for="(item, index) in metadata.CompetingGoodsBrandB_BaseList"
                  :key="index"
                  :name="item.Key"
                >
                  {{ item.Value }}
                </u-checkbox>
              </view>
            </u-checkbox-group>
            <u-line></u-line>
          </block>

          <block v-if="selectedFields.includes(12) || displayAll">
            <view class="u-text-left u-p-l-20">国产品牌数: {{ count_C }}</view>
            <u-checkbox-group @change="onCompetingGoodsBrandCChange">
              <view class="grid-2">
                <u-checkbox
                  :label-size="26"
                  v-model="item.checked"
                  v-for="(item, index) in metadata.CompetingGoodsBrandC_BaseList"
                  :key="index"
                  :name="item.Key"
                >
                  {{ item.Value }}
                </u-checkbox>
              </view>
            </u-checkbox-group>
          </block>
        </u-cell-item>

        <u-cell-item
          v-if="(selectedFields.includes(13) || displayAll) && level != 3"
          required
          :arrow="false"
          :title="addPrefix('上年BDR销售额')"
        >
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                type="number"
                inputAlign="right"
                placeholder="请输入"
                v-model.number="form.Dealer_OtherInfo.LastYearsBDRSales"
              ></u-input>
              <text class="unit u-m-l-32">万元</text>
            </view>
            <text class="desc">*BDR品牌的年销售额，新开的可预估</text>
          </view>
        </u-cell-item>

        <u-cell-item
          v-if="(selectedFields.includes(14) || displayAll) && level != 3"
          required
          :arrow="false"
          :title="addPrefix('总销售额')"
        >
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                type="number"
                inputAlign="right"
                placeholder="请输入"
                v-model.number="form.Dealer_OtherInfo.TotalSales"
              ></u-input>
              <text class="unit u-m-l-32">万元</text>
            </view>
            <text class="desc">*所有品类的年销售额</text>
          </view>
        </u-cell-item>
        <u-cell-item
          v-if="selectedFields.includes(15) || displayAll"
          required
          :arrow="false"
          :title="addPrefix('BDR销售额占比')"
        >
          <view class="u-flex-col u-col-bottom">
            <view>
              <text>
                {{
                  !form.Dealer_OtherInfo.TotalSales
                    ? ''
                    : ((form.Dealer_OtherInfo.LastYearsBDRSales / form.Dealer_OtherInfo.TotalSales) * 100).toFixed(0)
                }}%
              </text>
              <text class="unit"></text>
            </view>
            <text class="desc">*上年BDR销售额/总销售额</text>
          </view>
        </u-cell-item>

        <block v-if="level == 3">
          <u-cell-item
            v-if="selectedFields.includes(34) || displayAll"
            :arrow="false"
            title="上一年对应代理商供暖销售额"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_DealerHeatingSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item
            v-if="selectedFields.includes(35) || displayAll"
            :arrow="false"
            title="上一年对应代理商空凋销售额"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_DealerAirConditionerSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item
            v-if="selectedFields.includes(36) || displayAll"
            :arrow="false"
            title="上一年对应代理商净水销售额"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_DealerPurifiedWaterSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item v-if="selectedFields.includes(50) || displayAll" :arrow="false" title="上一年门店供暖销售额">
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_StoreHeatingSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item v-if="selectedFields.includes(51) || displayAll" :arrow="false" title="上一年门店空凋销售额">
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_StoreAirConditionerSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item v-if="selectedFields.includes(52) || displayAll" :arrow="false" title="上一年门店净水销售额">
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_Store_BDR_PurifiedWaterSales"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">万元</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item
            v-if="selectedFields.includes(53) || displayAll"
            :arrow="false"
            title="上一年销售BDR供暖产品台数"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_Store_BDR_HeatingSalesNum"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">台</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item
            v-if="selectedFields.includes(54) || displayAll"
            :arrow="false"
            title="上一年销售BDR净水产品台数"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_Store_BDR_AirConditionerSalesNum"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">台</text>
              </view>
            </view>
          </u-cell-item>

          <u-cell-item
            v-if="selectedFields.includes(55) || displayAll"
            :arrow="false"
            title="上一年销售BDR热泵产品台数"
          >
            <view class="u-flex-col u-col-bottom">
              <view class="u-flex">
                <u-input
                  v-model="form.Dealer_OtherInfo.LY_Store_BDR_PurifiedWaterSalesNum"
                  type="number"
                  inputAlign="right"
                  placeholder="请输入"
                ></u-input>
                <text class="unit u-m-l-32">台</text>
              </view>
            </view>
          </u-cell-item>
        </block>
      </block>

      <u-cell-item v-if="(selectedFields.includes(16) || displayAll) && level != 3" :arrow="false" title="人员数量">
        <view class="u-flex-col u-col-bottom">
          <view>
            <u-input inputAlign="right" v-model.number="form.Dealer_OtherInfo.PeopleNum" placeholder="请输入"></u-input>
            <text class="unit"></text>
          </view>
          <text class="desc">*不含售后安装人员</text>
        </view>
      </u-cell-item>

      <u-cell-item :title="addPrefix('等级')" :arrow="false" v-if="showLevel">
        <u-radio-group v-model="form.Dealer_OtherInfo.DealerGrade" :disabled="!showLevel">
          <u-radio :name="item.Key" v-for="(item, index) in metadata.DealerGrade_BaseList" :key="index">
            {{ item.Value }}
          </u-radio>
        </u-radio-group>
      </u-cell-item>

      <template v-if="showReview && level != 3">
        <u-section v-if="showSection" class="section" title="审核信息" :right="false"></u-section>
        <!-- <u-cell-group :border="false">
					<u-cell-item title="审核状态" :arrow="false" :value="form.DealerAuditInfo.AuditStateName"></u-cell-item>
					<view class="u-p-l-40">
						<u-cell-group :border="false"><review-flow :data="form.AuditForList"></review-flow></u-cell-group>
					</view>
				</u-cell-group> -->
      </template>

      <template v-if="showApplyReason">
        <u-cell-item :arrow="false" title="申请原因">
          <u-radio-group v-model="form.ApplyForReasonId">
            <view class="grid-2">
              <u-radio
                :label-size="26"
                v-for="(item, index) in metadata.DealerApplyFor_BaseList"
                :name="item.Key"
                :key="index"
              >
                {{ item.Value }}
              </u-radio>
            </view>
          </u-radio-group>
        </u-cell-item>
        <u-cell-item v-if="form.ApplyForReasonId == 3" :arrow="false" title="物料需求">
          <u-checkbox-group @change="onRequirementsChange">
            <view class="grid-2">
              <u-checkbox
                :label-size="26"
                v-model="item.checked"
                v-for="(item, index) in metadata.DealerMaterialRequirements_BaseList"
                :name="item.Key"
                :key="index"
              >
                {{ item.Value }}
              </u-checkbox>
            </view>
          </u-checkbox-group>
        </u-cell-item>
        <u-cell-item v-if="form.ApplyForReasonId == 4" :arrow="false" title="费用需求">
          <u-checkbox-group @change="onRequirementsChange">
            <view class="grid-2">
              <u-checkbox
                :label-size="26"
                v-model="item.checked"
                v-for="(item, index) in metadata.DealerMoneyRequirements_BaseList"
                :name="item.Key"
                :key="index"
              >
                {{ item.Value }}
              </u-checkbox>
            </view>
          </u-checkbox-group>
        </u-cell-item>

        <u-cell-item v-if="form.ApplyForReasonId == 5" :arrow="false" title="其他备注">
          <u-input
            :customStyle="customStyle"
            v-model="form.OtherNote"
            :autoHeight="true"
            type="textarea"
            inputAlign="right"
            placeholder="其他备注"
          ></u-input>
        </u-cell-item>
      </template>
    </u-cell-group>
  </view>
</template>

<script>
export default {
  props: {
    level: {
      type: Number,
      default: 1
    },
    showAccount: {
      type: Boolean,
      default: true
    },
    showSection: {
      type: Boolean,
      default: false
    },
    showReview: {
      type: Boolean,
      default: true
    },
    showDeliveryAddress: {
      type: Boolean,
      default: true
    },
    showParent: {
      type: Boolean,
      default: true
    },
    showApplyReason: {
      type: Boolean,
      default: false
    },
    loadCity: {
      type: Boolean,
      default: true
    },
    showLevel: {
      type: Boolean,
      default: true
    },
    selectedFields: {
      type: Array,
      default() {
        return [];
      }
    },
    showCCType: {
      type: Boolean,
      default: false
    },
    showChannelType: {
      type: Boolean,
      default: false
    },
    displayAll: {
      type: Boolean,
      default: true
    },
    showSalesInfo: {
      type: Boolean,
      default: false
    },
    showBrand: {
      type: Boolean,
      default: false
    },
    metadata: {
      type: Object,
      default() {
        return {
          BusinessCategory_BaseList: [],
          CompetingGoodsBrandA_BaseList: [],
          CompetingGoodsBrandB_BaseList: [],
          CompetingGoodsBrandC_BaseList: [],
          DealerApplyFor_BaseList: [],
          DealerGrade_BaseList: [],
          DealerMaterialRequirements_BaseList: [],
          DealerMoneyRequirements_BaseList: [],
          DealerShutDown_BaseList: [],
          DealerType_BaseList: [],
          DealerAndGoReason_BaseList: []
        };
      }
    },
    data: {
      type: Object,
      default() {
        return {};
      }
    }
  },

  data() {
    return {
      customStyle: {
        fontSize: '26rpx'
      },
      licenseFileList: [],
      treatyPhotoFileList: [],

      form: {
        ApplyForReasonId: null,
        Requirements: '',
        OtherNote: '',
        Remark: '',

        Dealer_BaseInfo: {
          // 	点击列表进入的经销商ID
          DealerId: null,
          // 	名称
          Name: null,
          // 	简称
          Referred: '',
          // 	账号 默认赋值 "" 空字符串
          Account: '',
          // 金蝶编码
          KeDealerNo: '',
          // 	负责人
          NickName: '',
          // 	手机号
          Mobile: '',
          // 	联系电话
          Telephone: '',
          Level: this.level,
          LevelName: '',
          // 	省
          ProvinceId: null,
          // 	市
          CityId: null,
          // 区
          DistrictId: null,
          //详细地址
          Address: '',

          Store_Location: '',
          Store_Location_Other: '',

          // 收货地址
          Delivery_ProvinceId: null,
          Delivery_CityId: null,
          Delivery_DistrictId: null,
          Delivery_Address: '',
          Parent_DealerId: null,
          Parent_Name: '',
          State: null,
          Created: null,
          IsFictitious: null
        },
        Dealer_OtherInfo: {
          // 	属性 1.零售 2.工程 0.不选 单选
          DealerType: null,
          // 	经营品类 分解逗号在用 多选
          BusinessCategory: '',
          // 竞品品牌 - BDR品牌 分解逗号在用 多选
          CompetingGoodsBrandA: '',
          // 竞品品牌 - 进口品牌 分解逗号在用 多选
          CompetingGoodsBrandB: '',
          // 竞品品牌 - 国产品牌 分解逗号在用 多选
          CompetingGoodsBrandC: '',
          // 上年BDR销售额 单位是固定的 温改、金蝶 TAB都是固定的 改动少 后端就不输出了
          LastYearsBDRSales: null,
          // 	总销售额 单位是固定的
          TotalSales: null,
          // BDR销售额占比 1.单位是固定的 % 2.这个着重说一下 这个字段什么界面都是禁止填写状态 加载界面的时候直接取值就完事，但是新增或者编辑的时候 这个字段是 由LastYearsBDRSales/TotalSales upkey事件计算的
          PercentageBDRSales: null,
          // 人员数量 单位是固定的
          PeopleNum: null,
          // 	一级等级 ABC那个
          DealerGrade: null,
          // 经销商证件照
          BusinessLicenseA: '',
          // 经销商协议
          TreatyPhoto: '',
          // 经销商协议类型 1.图片 4.文件（文件直接href跳转）
          TreatyPhotoType: null,
          // 是否签约服务商 1是 2否 这个是金蝶TAB最后一行 设计稿名字错了。
          IsSign: null,

          // 	生日祝福备注 ------------老板模块
          BlessingNote: '',
          // 老板姓名
          BossName: '',
          // 老板手机号
          BossPhone: '',
          // 	老板生日
          BossBirthday: null,
          // 	是否VIP
          IsVIP: null,

          Store_Location: '', //门店位置
          Store_Location_Other: '', //门店其他位置
          BDR_Area: '', //BDR面积
          Store_Area: '', //店内总面积
          OtherProductArea: '', // 其他产品占地面积

          LY_DealerHeatingSales: '',
          LY_DealerAirConditionerSales: '',
          LY_DealerPurifiedWaterSales: '',
          LY_StoreHeatingSales: '',
          LY_StoreAirConditionerSales: '',
          LY_Store_BDR_PurifiedWaterSales: '',
          LY_Store_BDR_HeatingSalesNum: '',
          LY_Store_BDR_AirConditionerSalesNum: '',
          LY_Store_BDR_PurifiedWaterSalesNum: '',

          CC_Type: ''
        },
        DealerAuditInfo: {
          ApplayRemark: '',
          ApplayTime: '',
          AuditState: '',
          AuditStateName: '',
          FinalAuditNote: '',
          FirstAuditNote: '',
          ReviewAuditNote: ''
        },
        AuditForList: []
      },
      areaCode: [],

      showLocationPicker: false,
      locationIndex: -1,
      location: {},
      Store_Location_List: []
    };
  },

  mounted() {
    console.log('data', this.metadata);
  },

  methods: {
    onLocationChange(e) {
      if (!e[0].value || !e[0].label) {
        if (this.Store_Location_List.length > 0) {
          this.location.value = this.Store_Location_List[0].Key;
          this.location.label = this.Store_Location_List[0].Value;
        } else {
          return false;
        }
      } else {
        this.location = e[0];
      }

      this.locationIndex = this.Store_Location_List.findIndex(item => item.Key == this.location.value);
      this.form.Dealer_OtherInfo.Store_Location = this.location.value;
    },

    initForm(data) {
      if (data.Dealer_BaseInfo) {
        this.form.Dealer_BaseInfo = Object.assign(this.form.Dealer_BaseInfo, data.Dealer_BaseInfo);

        if (data.Dealer_BaseInfo.ProvinceId) {
          this.areaCode[0] = data.Dealer_BaseInfo.ProvinceId;
        }
        if (data.Dealer_BaseInfo.CityId) {
          this.areaCode[1] = data.Dealer_BaseInfo.CityId;
        }
        if (data.Dealer_BaseInfo.DistrictId) {
          this.areaCode[2] = data.Dealer_BaseInfo.DistrictId;
        }
      }
      if (data.Dealer_OtherInfo) {
        this.form.Dealer_OtherInfo = Object.assign(this.form.Dealer_OtherInfo, data.Dealer_OtherInfo);

        if (data.Dealer_OtherInfo.BusinessLicenseA) {
          this.licenseFileList.push({ url: this.$getImageUrl(data.Dealer_OtherInfo.BusinessLicenseA) });
        }
        if (data.Dealer_OtherInfo.TreatyPhoto) {
          this.treatyPhotoFileList.push({ url: this.$getImageUrl(data.Dealer_OtherInfo.TreatyPhoto) });
        }
      }
      if (data.DealerAuditInfo) {
        this.form.DealerAuditInfo = data.DealerAuditInfo;
      }

      if (data.AuditForList) {
        this.form.AuditForList = data.AuditForList;
      }

      if (data.Store_Location_List) {
        this.Store_Location_List = data.Store_Location_List;

        let locIndex = data.Store_Location_List.findIndex(
          item => item.Key == this.form.Dealer_OtherInfo.Store_Location
        );
        this.locationIndex = locIndex;
        if (locIndex > -1) {
          this.location.label = data.Store_Location_List[locIndex].Value;
          this.location.value = data.Store_Location_List[locIndex].Key;
        }
      }

      console.log(this.form);
    },

    addPrefix(text) {
      let prefix = '';
      if (this.level == 1) {
        prefix = '一级';
      }
      if (this.level == 2) {
        prefix = '二级';
      }
      if (this.level == 3) {
        prefix = '门店';
      }
      return prefix + text;
    },

    onRequirementsChange(e) {
      this.form.Requirements = e.toString();
    },

    onLicenseChange(files, name) {
      this.$fileUpload(files[0].file).then(res => {
        this.form.Dealer_OtherInfo.BusinessLicenseA = res.key;
      });
    },

    onTreatyPhotoChange(files, name) {
      this.$fileUpload(files[0].file).then(res => {
        this.form.Dealer_OtherInfo.TreatyPhoto = res.key;
      });
    },

    onTreatyPhotoFileChange(e) {
      if (e.length > 0) {
        this.form.Dealer_OtherInfo.TreatyPhoto = e[0].JumpUrl;
      }
    },

    onRemoveTreatyPhoto() {
      this.form.Dealer_OtherInfo.BusinessLicenseA = '';
    },

    onRemoveLicense() {
      this.form.Dealer_OtherInfo.TreatyPhoto = '';
    },

    onCityChange(e) {
      if (e.province) {
        this.form.Dealer_BaseInfo.ProvinceId = e.province.value;
      }
      if (e.city) {
        this.form.Dealer_BaseInfo.CityId = e.city.value;
      }
      if (e.area) {
        this.form.Dealer_BaseInfo.DistrictId = e.area.value;
      }
    },

    onBusinessCategoryChange(e) {
      this.form.Dealer_OtherInfo.BusinessCategory = e.toString();
    },
    onCompetingGoodsBrandAChange(e) {
      this.form.Dealer_OtherInfo.CompetingGoodsBrandA = e.toString();
    },
    onCompetingGoodsBrandBChange(e) {
      this.form.Dealer_OtherInfo.CompetingGoodsBrandB = e.toString();
    },
    onCompetingGoodsBrandCChange(e) {
      this.form.Dealer_OtherInfo.CompetingGoodsBrandC = e.toString();
    },

    toViewFile(file) {
      window.location.href = this.$getImageUrl(file);
    }
  },

  computed: {
    count_A() {
      if (!this.metadata.CompetingGoodsBrandA_BaseList) {
        return 0;
      }
      return this.metadata.CompetingGoodsBrandA_BaseList.filter(item => item.checked).length;
    },
    count_B() {
      if (!this.metadata.CompetingGoodsBrandB_BaseList) {
        return 0;
      }
      return this.metadata.CompetingGoodsBrandB_BaseList.filter(item => item.Key != 80).filter(item => item.checked)
        .length;
    },
    count_C() {
      if (!this.metadata.CompetingGoodsBrandC_BaseList) {
        return 0;
      }
      return this.metadata.CompetingGoodsBrandC_BaseList.filter(item => item.Key != 81).filter(item => item.checked)
        .length;
    }
  }
};
</script>

<style lang="scss" scoped>
.u-delete-icon {
  position: absolute;
  top: 10rpx;
  right: 10rpx;
  z-index: 10;
  background-color: $u-type-error;
  border-radius: 100rpx;
  width: 44rpx;
  height: 44rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
